package iface

import (
	"context"
	"time"
)

// Cache 通用缓存接口
type IDataCache interface {
	// Set 基础操作
	Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
	Get(ctx context.Context, key string) (interface{}, error)
	Delete(ctx context.Context, key string) error
	Exists(ctx context.Context, key string) (bool, error)

	// 主键操作
	SetWithPrimaryKey(ctx context.Context, primaryKey string, value interface{}, ttl time.Duration) error
	GetByPrimaryKey(ctx context.Context, primaryKey string) (interface{}, error)

	// 索引操作
	AddIndex(ctx context.Context, indexName string, indexKey string, primaryKey string) error
	GetByIndex(ctx context.Context, indexName string, indexKey string) ([]interface{}, error)
	RemoveIndex(ctx context.Context, indexName string, indexKey string, primaryKey string) error

	// 清理过期项
	CleanExpired(ctx context.Context) error

	// 统计
	Stats() CacheStats
}

// CacheStats 缓存统计信息
type CacheStats struct {
	Hits      int64
	Misses    int64
	Size      int64
	Expired   int64
	Evictions int64
}

// CacheType 缓存类型
type CacheType int

const (
	MemoryCache CacheType = iota
	RedisCache
)

// Config 缓存配置
type Config struct {
	Type          CacheType
	MaxItems      int           // 内存缓存最大项数
	DefaultExpiry time.Duration // 默认过期时间
	RedisConfig   RedisConfig   // Redis配置
}

// RedisConfig Redis配置
type RedisConfig struct {
	Addr     string
	Password string
	DB       int
}
